#ifndef __MY_COIL_H__
#define __MY_COIL_H__
#include "s_platform.h"//////////////////////
#include "modbus.h"
typedef struct my_coil my_coil_t;
typedef enum{COIL_TYPE_NOT_EXIST=0, COIL_TYPE_IN, COIL_TYPE_OUT}COIL_TYPE_E;
typedef COIL_TYPE_E (*p_get_coil_type)(uint16_t index);
typedef uint8_t (*p_get_coil_val)(uint16_t index);
typedef void (*p_set_coil_val)(uint8_t value, uint16_t index);


typedef struct {
    uint16_t table_len;
    uint8_t* type_table;
    uint8_t* value_table;
    uint8_t* temp_out_table;
    uint8_t* online_table;
    uint8_t* NONC_table;
}coil_table_t;

void my_coil_destroy(my_coil_t* me);




my_coil_t* my_coil_creat(uint16_t coil_sum, p_get_coil_type get_coil_type, p_get_coil_val get_coil_val, p_set_coil_val set_coil_val);


COIL_TYPE_E my_coil_get_type(my_coil_t* me, uint16_t index);



void my_coil_updata_type(my_coil_t* me);

void my_coil_read_status(my_coil_t* me, uint8_t use_out_temp);

int my_coil_write_out_single(my_coil_t* me, uint8_t value, uint16_t index);

void my_coil_write_out_multy(my_coil_t* me, uint8_t* table, uint8_t start_index, uint8_t len);

int my_coil_set_nonc_single(my_coil_t* me, uint8_t value, uint16_t index);

void my_coil_set_nonc_multy(my_coil_t* me, uint8_t* table, uint8_t start_index, uint8_t len);

coil_table_t* my_coil_get_table(my_coil_t* me);

void my_coil_update_libmodbus(my_coil_t* me, modbus_mapping_t* map);


int modbus_data_update(uint16_t coil_sum, modbus_mapping_t *mb_mapping);




#endif


